"""
URL configuration for dnsadmin project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import logout
from django.shortcuts import redirect
from django.http import HttpRequest

# 自定义管理界面标题
admin.site.site_header = "DNS管理系统 - 管理后台"
admin.site.site_title = "DNS管理系统"
admin.site.index_title = "欢迎使用DNS管理系统"

# 自定义logout视图，支持GET和POST请求
def custom_logout(request):
    """自定义登出视图，支持GET和POST请求"""
    logout(request)
    return redirect('/')

urlpatterns = [
    # 管理后台
    path('admin/', admin.site.urls),
    
    # 用户认证
    path('login/', auth_views.LoginView.as_view(
        template_name='registration/login.html',
        redirect_authenticated_user=True
    ), name='login'),
    path('logout/', custom_logout, name='logout'),
    
    # DNS管理应用
    path('', include('dns_manager.urls')),
]

# 开发环境静态文件服务
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS[0] if settings.STATICFILES_DIRS else None)
